package eu.jpereira.trainings.designpatterns.creational.builder.xml;

import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.ReportBulider;

public class XMLBulider implements ReportBulider {

	private XMLReportBody reportBody;
	private boolean start = true;
	private boolean start0 = true;
	public XMLBulider() {
		
		reportBody = new XMLReportBody();
	}
	
    
	
	
	
	public ReportBulider setCustomerName(String customerName) {
		
		reportBody.putContent("<sale><customer><name>");
		reportBody.putContent(customerName);
		reportBody.putContent("</name>");
		return this;
	}

	public ReportBulider setCustomerPhone(String phoneNumber) {
		
		reportBody.putContent("<phone>");
		reportBody.putContent(phoneNumber);
		reportBody.putContent("</phone>");
		
		return this;
	}

	public ReportBulider end() {
		
		if (!start) {
			
			reportBody.putContent("</items>");
			reportBody.putContent("</sale>");
		}
		
		return this;
	}

	public ReportBulider addItem(String name, int quantity, double price) {
		if (start) {reportBody.putContent("</customer>");
			reportBody.putContent("<items>");
			start = false;
		}
		reportBody.putContent("<item><name>");
		reportBody.putContent(name);
		reportBody.putContent("</name><quantity>");
		reportBody.putContent(quantity);
		reportBody.putContent("</quantity><price>");
		reportBody.putContent(price);
		reportBody.putContent("</price></item>");
		return this;
	}

	
	
	public ReportBody getReportBody() {
		
		return reportBody;
	}
}
